Ext.namespace('VAS');

VAS.DetailTabPanel=Ext.extend(Ext.FormPanel, {


	initComponent : function() {
		var _this=this;
		var config={
		url:'http/grid.json',

        items : {
						xtype : 'tabpanel',
						deferredRender:false,
						layoutOnTabChange: true,
						activeTab:0, 
						defaults : {
							autoHeight : true,
							bodyStyle : 'padding:10px'
						},
						
						items : _this.getTabs()}
		}
		this.on('show',function(){alert(1)});
		Ext.apply(this, config);
		Ext.apply(this.initialConfig, config);


	VAS.DetailTabPanel.superclass.initComponent.apply(this, arguments);
	},
	
	getTabs:function(){
		
		var _data=this.config.detailWin.tabsPanel;
		var _tabs=[];
		var _tabPanels=_data.items;
		var _length=_tabPanels.length;
		   
		
      var _data=SyncAjax(_data.url);		

		for(var i=0;i<_length;i++){
            _tabPanels[i].xtype='form',
            _tabPanels[i].layout='form',
			_tabPanels[i].items=new Ext.ux.FieldSet({
								columnWidth : _data.fieldSet.items[i].columnWidth,
								labelWidth : _data.fieldSet.items[i].labelWidth,
								fieldSetItems :_data.fieldSet.items[i].items 
							});
			_tabs.push(_tabPanels[i])
		}
		return _tabs;
		
		
	}
	
});



VAS.DynamicDetailWindow = function($config) {
	var _this = this;
	

	var _win=$config.config.detailWin;
	var _record=$config.config.detailWin;
	_this._tbarId=$config.config.tbarId;
	
	_this.detail=new VAS.DetailTabPanel($config);
	

  
	var thisConfig = {
//		id:'adss_972394823',
		title:$config.config.detailWin.title,
		heigth:$config.config.detailWin.heigth,
		width:$config.config.detailWin.width,		
		closeAction : 'close',
		alwaysOnTop : true,
		modal : true,	
		items:_this.detail
		,buttons:{items:[{text:'保存',	handler : function() {                    
				if (_this.detail.getForm().isValid()) {
					_this.detail.getForm().submit({
						url : _win.tabsPanel.action,
						waitTitle : '正在提交',
						waitMsg : '正在向服务器发送请求',
						clientValidation : true,
						success : function(form, action) {
							Ext.Msg.alert('提示', '提交保存成功!', function() {
										_this.detail.getForm()
												.reset();
									});

						},
						failure : function(form, action) {
							if (action.failureType == Ext.form.Action.CLIENT_INVALID) {
								Ext.Msg.alert('提示', '输入的信息不符合规格，请按照提示重新输入！');
							} else {
								alertFailure(action.result.data);
							}
						},
					params:{tbarId:_this._tbarId}
					});
				} else {
					Ext.Msg.alert('提示', '请填入必填项');
				}

			}
			}, {
				text : '关闭',
				handler : function() {
					_this.close();
				}
			},
			 {
				text : 'Load',
				handler : function() {
				alert(_this.detail.form.load({url:'http/grid.json'}));
				}
			}]}
	
		
  
	};
	var _config = $config || {};
	
//	_this.render(Ext.getBody());

//var _tabs=_this.detail.items.itemAt(0);
//Ext.each(_tabs.items,function(tabs){      
//	                                // for each tab in the panel
//                _tabs.activate(tabs);           // call the activate() method
//            })
//	
	
//  _this.detail.form.load({url:'http/grid.json'})
//	
//            alert(_this.detail.getForm().getEl().dom);
  
	Ext.apply(_this, Ext.apply(thisConfig, _config));
	
	VAS.DynamicDetailWindow.superclass.constructor.call(_this);

};

Ext.extend(VAS.DynamicDetailWindow,Ext.Window,{
manager:wgroup
	 
		});
Ext.reg('dynamicDetail-win',VAS.DynamicDetailWindow);



